package com.ruoyi.integration.mqtt.config;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @Description : MQTT回调
 * @Author : Bruce Lee
 * @CreateTime : 2025/2/17
 */

@Slf4j
public class CustomMqttCallback implements MqttCallback {

    @Override
    public void connectionLost(Throwable throwable) {
        log.error("与服务器连接断开，可以做重连");
    }

    @Override
    public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
        log.info("接收消息主题 : " + s);
        log.info("接收消息内容 : " + new String(mqttMessage.getPayload()));
        /**
         * TODO 消息处理逻辑
         */

    }

    @SneakyThrows
    @Override
    public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
        log.info("消息发送成功");
    }
}
